class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


node1 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
node1.next = node2
node2.next = node3
node3.next = node4

cur1 = node1
while cur1.next:
    print(cur1.val)
    cur1 = cur1.next
cur2 = node1
while cur2:
    print(cur2.val)
    cur2 = cur2.next